package com.heima.day08;

import java.util.Scanner;

/*
* 2、【编号：802】 已知用户名和密码，请用
* 程序实现模拟用户登录。总共给三次机
* 会，是否登录成功，给出相应的提示。
* */
public class Login {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请您设置登录的账户:");
        String root = sc.nextLine();
        System.out.println("请您设置登录的密码:");
        String pass = sc.nextLine();
        Register re = new Register(root, pass);
        for (int i = 1; i <= 3; i++) {
            System.out.println("请输入您要登录的账户:");
            root = sc.nextLine();
            System.out.println("请输入您要登录的密码:");
            pass = sc.nextLine();
            if (re.login(root, pass) == true) {
                System.out.println("!!!恭喜您!!!");
                break;
            } else {
                if (i == 3) {
                    System.out.println("您今天已经没有登陆的机会了!");
                }
                System.out.println("你还剩" + (3 - i) + "登陆的机会!"); } } }}

class Register {
    private String root;
    private String pass;

    public Register(String root, String pass) {
        this.root = root;
        this.pass = pass;
    }

    public Boolean login(String root, String pass) {
        System.out.println(this.root + " " + root + " " + this.pass + " " + pass);
        if(this.root==root&&this.pass==pass){
            System.out.println("登录成功!");
            return true;
        }else{
            System.out.println("不好意思,你这次登录失败了!");
            return false;
        }
    }
}
